package com.liu.netty.service;

import com.liu.netty.dao.DriverDao;
import com.liu.netty.dao.DriverParamsDao;
import com.liu.netty.entity.Driver;
import com.liu.netty.entity.DriverParams;
import com.liu.netty.pojo.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import util.IdWorker;

import javax.transaction.Transactional;


@Service
@Slf4j
@Transactional
public class DriverParamsService {

    @Autowired
    private DriverParamsDao driverParamsDao;

    @Autowired
    private DriverDao driverDao;
    @Autowired
    private IdWorker idWorker;


    public void saveOrUpDateDriverParams(DriverParams driverParams,String objectAddress){
        Driver driver = driverDao.findByObjectAddress(objectAddress);
       DriverParams driverParams1 = driverParamsDao.findByDriver(driver.getId());
       if(driverParams1 ==null){
           driverParams.setId(idWorker.nextId()+"");
       }


        driverParamsDao.save(driverParams);

    }

    public void addDriverParamsFromClient(Message message){
        DriverParams params = new DriverParams();
        BeanUtils.copyProperties(message,params);


    }


}
